#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int minimumRounds(vector<int>& tasks) {
        unordered_map<int, int> hsh;
        for (int i = 0; i < tasks.size(); i++) hsh[tasks[i]]++;
        int ans = 0;
        for (auto& t : hsh)
        {
            int e = t.second;
            if (e == 1) return -1;
            if (e % 3 == 0) ans += e / 3;
            if (e % 3 == 1) ans += (e / 3 - 1) + 2;
            if (e % 3 == 2) ans += (e / 3) + 1;
        }
        return ans;
    }
};